import Vue from 'vue'
import VueRouter from 'vue-router'
import Main from "@/components/Main";

//管理员管理模块
import admin_main from "@/components/pages/admin/admin_main";

//院校信息管理模块
import colleges_main from "@/components/pages/colleges/colleges_main";
import college_grade from "@/components/pages/colleges/sort/college_grade";
import college_info from "@/components/pages/colleges/sort/college_info";
import academic_grades from "@/components/pages/colleges/sort/grades_sort/academic_grades";
import profession_grades from "@/components/pages/colleges/sort/grades_sort/profession_grades";

//交流讨论社区管理模块
import discussion_main from "@/components/pages/discussion/discussion_main";
import post_comment from "@/components/pages/discussion/sort/post_comment";
import post_info from "@/components/pages/discussion/sort/post_info";

//考研信息管理模块
import information_main from "@/components/pages/information/information_main";

//闲置转卖管理模块
import resale_main from "@/components/pages/resale/resale_main";
import item_comment from "@/components/pages/resale/sort/item_comment";
import item_info from "@/components/pages/resale/sort/item_info";
import deals from "@/components/pages/resale/deals";

//积分社区管理模块
import score_main from "@/components/pages/score/score_main";

//用户管理模块
import user_main from "@/components/pages/user/user_main";
import account_info from "@/components/pages/user/sort/account_info";
import basic_info from "@/components/pages/user/sort/basic_info";
import identity_info from "@/components/pages/user/sort/identity_info";

//首页
import show_main from "@/components/pages/show_main";

import login from "@/components/pages/login";


Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    name:'login',
    component:login
  },
  {
    path: '/Main',
    name: Main,
    component: Main,
    children:[
      {
        path:'/Main/Show_Main',
        name:'Show_Main',
        component:show_main
      },
      //  管理员管理
      {
        path:'/Main/Admin_Main',
        name:'Admin_Main',
        component:admin_main
      },
      //  院校信息管理
      {
        path:'/Main/Colleges_Main',
        name:'Colleges_Main',
        component:colleges_main,
        children:[
          {
            path:'/Main/Colleges_Main/College_Info',
            name:'College_Info',
            component:college_info
          },
          {
            path:'/Main/Colleges_Main/College_Grade',
            name:'College_Grade',
            component:college_grade,
            children:[
              {
                path:'/Main/Colleges_Main/College_Grade/Academic_Grades',
                name:'Academic_Grades',
                component:academic_grades,
              },
              {
                path:'/Main/Colleges_Main/College_Grade/Profession_Grades',
                name:'Profession_Grades',
                component:profession_grades,
              }
            ]
          },
        ]
      },
      //  交流讨论社区管理
      {
        path:'/Main/Discussion_Main',
        name:'Discussion_Main',
        component:discussion_main,
        children:[
          {
            path:'/Main/Discussion_Main/Post_Info',
            name:'Post_Info',
            component:post_info
          },
          {
            path:'/Main/Discussion_Main/Post_Comment',
            name:'Post_Comment',
            component:post_comment
          },
        ]
      },
      //  考研信息管理
      {
        path:'/Main/Information_main',
        name:'Information_main',
        component:information_main
      },
      //  闲置物品信息管理
      {
        path:'/Main/Resale_Main',
        name:'Resale_Main',
        component:resale_main,
        children:[
          {
            path:'/Main/Resale_Main/Item_Info',
            name:'Item_Info',
            component:item_info
          },
          {
            path:'/Main/Resale_Main/Item_Comment',
            name:'Item_Comment',
            component:item_comment
          },
          {
            path:'/Main/Resale_Main/Deals',
            name:'Deals',
            component:deals
          },
        ]
      },
      //  积分中心管理
      {
        path:'/Main/Score_Main',
        name:'Score_Main',
        component:score_main
      },
      //  用户管理
      {
        path:'/Main/User_Main',
        name:'User_Main',
        component:user_main,
        children:[
          {
            path:'/Main/User_Main/Basic_Info',
            name:'Basic_Info',
            component:basic_info
          },
          {
            path:'/Main/User_Main/Account_Info',
            name:'Account_Info',
            component:account_info
          },
          {
            path:'/Main/User_Main/Identity_Info',
            name:'Identity_Info',
            component:identity_info
          },
        ]
      },


    ]
  },




]

const router = new VueRouter({
  routes
})

// 前端路由守卫判断是否登录
router.beforeEach((to,from,next)=>{
  if(to.path==='/')
  {
    next();
  }
  if(!window.sessionStorage.getItem('token') || window.sessionStorage.getItem('token')==null || window.sessionStorage.getItem('token')===''|| window.sessionStorage.getItem('token')===undefined)
  {
    next('/');
  }
  next();
})

export default router
